package com.yanfan.ccapi.controller;

import com.yanfan.ccapi.service.ICcapiCustomMappingService;
import com.yanfan.ccapicode.dao.entity.CustomMappingDO;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 自定义映射模板Controller
 *
 * @author kerwincui
 * @date 2025-06-29
 */
@RestController
@RequestMapping("/ccapi/customMapping")
@Api(tags = "自定义映射模板")
public class CcapiCustomMappingController extends BaseController {
    @Autowired
    private ICcapiCustomMappingService ccapiCustomMappingService;

    /**
     * 查询自定义映射模板列表
     */
//@PreAuthorize("@ss.hasPermi('ccapi:customMapping:list')")
    @GetMapping("/list")
    @ApiOperation("查询自定义映射模板列表")
    public TableDataInfo list(CustomMappingDO ccapiCustomMapping) {
        startPage();
        List<CustomMappingDO> list = ccapiCustomMappingService.selectCcapiCustomMappingList(ccapiCustomMapping);
        return getDataTable(list);
    }

    /**
     * 导出自定义映射模板列表
     */
    @ApiOperation("导出自定义映射模板列表")
    //@PreAuthorize("@ss.hasPermi('ccapi:customMapping:export')")
    @Log(title = "自定义映射模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomMappingDO ccapiCustomMapping) {
        List<CustomMappingDO> list = ccapiCustomMappingService.selectCcapiCustomMappingList(ccapiCustomMapping);
        ExcelUtil<CustomMappingDO> util = new ExcelUtil<CustomMappingDO>(CustomMappingDO.class);
        util.exportExcel(response, list, "自定义映射模板数据");
    }

    /**
     * 获取自定义映射模板详细信息
     */
    //@PreAuthorize("@ss.hasPermi('ccapi:customMapping:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取自定义映射模板详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ccapiCustomMappingService.selectCcapiCustomMappingById(id));
    }

    /**
     * 新增自定义映射模板
     */
    //@PreAuthorize("@ss.hasPermi('ccapi:customMapping:add')")
    @Log(title = "自定义映射模板", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增自定义映射模板")
    public AjaxResult add(@RequestBody CustomMappingDO ccapiCustomMapping) {
        return toAjax(ccapiCustomMappingService.insertCcapiCustomMapping(ccapiCustomMapping));
    }

    /**
     * 修改自定义映射模板
     */
    //@PreAuthorize("@ss.hasPermi('ccapi:customMapping:edit')")
    @Log(title = "自定义映射模板", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改自定义映射模板")
    public AjaxResult edit(@RequestBody CustomMappingDO ccapiCustomMapping) {
        return toAjax(ccapiCustomMappingService.updateCcapiCustomMapping(ccapiCustomMapping));
    }

    /**
     * 删除自定义映射模板
     */
    //@PreAuthorize("@ss.hasPermi('ccapi:customMapping:remove')")
    @Log(title = "自定义映射模板", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除自定义映射模板")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ccapiCustomMappingService.deleteCcapiCustomMappingByIds(ids));
    }
}
